<?php

namespace App\Admin\Controllers;

use App\Models\Base\ServerList;
use App\Models\GameLog\LogTalk;
use Encore\Admin\Grid;
use Encore\Admin\Facades\Admin;
use Encore\Admin\Layout\Content;

class MessageController extends Controller
{
    /**
     * Index interface.
     *
     * @return Content
     */
    public function index()
    {
        return Admin::content(function (Content $content) {
            $content->header(trans('game.player_related'));
            $content->description(trans('game.role_chat_log'));

            $content->body($this->grid());
        });
    }

    /**
     * Make a grid builder.
     *
     * @return Grid
     */
    protected function grid()
    {
        return Admin::grid(LogTalk::class, function (Grid $grid) {
            $grid->model()->orderBy('time', 'desc');
            $grid->name(trans('game.role_name'));
            $grid->vip(trans('game.vip_lv'));
            $grid->recverid(trans('game.recipient'));
            $grid->channel(trans('game.channel'))->display(function ($channel) {
                return getChannel($channel);
            });
            $grid->content(trans('game.content'));
            $grid->voiceUrl(trans('game.voice_url'));
            $grid->voiceTime(trans('game.voice_time'));
            $grid->time(trans('admin.time'))->display(function ($time) {
                return date('Y-m-d H:i:s', $time);
            })->sortable();
            $grid->disableCreateButton();
            $grid->disableExport();
            $grid->disableActions();
            $grid->filter(function ($filter) {
                $filter->disableIdFilter();
                // 去掉默认的id过滤器
                $filter->setNotWhere(['server_id']);
                $filter->equal('server_id', trans('game.server_name'))->select(ServerList::all()->pluck('name', 'server_id'));
                $filter->like('name', trans('game.role_name'));
            });
        });
    }
}
